package com.pzhuweb.sgblog.controller;

import com.pzhuweb.sgblog.domain.entity.Comment;
import com.pzhuweb.sgblog.service.CommentService;
import com.pzhuweb.sgblog.domain.utils.ResponseResult;
import com.pzhuweb.sgblog.domain.utils.SystemConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 鄧浩奇
 * @classname CommentController
 * @description
 * @since 2023/6/21 15:40
 **/

@RestController
@RequestMapping("/comment")
@Api(description = "评论相关接口")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/commentList")
    @ApiOperation(value = "获取所有评论")
    @ApiImplicitParams({   // 这个注解是swagger2描述参数的
            @ApiImplicitParam(name = "articleId", value = "文章id"),
            @ApiImplicitParam(name = "pageNum", value = "页号"),
            @ApiImplicitParam(name = "pageSize", value = "一页里面的评论数目")
    })
    public ResponseResult<?> commentList(Long articleId, Integer pageNum, Integer pageSize) {
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT_TYPE, articleId, pageNum, pageSize);
    }

    @PostMapping
    @ApiOperation(value = "发送评论")
    @ApiImplicitParams({   // 这个注解是swagger2描述参数的
            @ApiImplicitParam(name = "comment", value = "发送评论的请求体"),
    })
    public ResponseResult<?> comment(@RequestBody Comment comment) {
        return commentService.addComment(comment);
    }

    @GetMapping("/linkCommentList")
    @ApiOperation("获取友链评论列表")
    @ApiImplicitParams({   // 这个注解是swagger2描述参数的
            @ApiImplicitParam(name = "pageNum", value = "页号"),
            @ApiImplicitParam(name = "pageSize", value = "一页里面的评论数目")
    })
    public ResponseResult<?> linkCommentList(Integer pageNum, Integer pageSize) {
        return commentService.commentList(SystemConstants.LINK_COMMENT_TYPE, null, pageNum, pageSize);
    }
}
